﻿#ifndef __AF_TIMER_H__
#define __AF_TIMER_H__

#include "AF_Define.h"

namespace AF
{
	//class RunBase
		class Timer;
}
typedef AF::Timer			AF_CTimer;

#include <memory>
#include "AF_Run.h"
#include "AF_Link.h"

namespace AF
{
	/// 定时器类
	class Timer : public RunBase
	{
	public:
		static void			UpdateTimers();
		static void			UpdateExactTimers();
	private:
		static void			AddTimer(Timer* pTimer);
		static void			RemoveTimer(Timer* pTimer);

	private:
		static Link<Timer*>		TimerLink;
		static Link<Timer*>		TimerExactLink;
		static unsigned int		NameID;

	public:
		Timer();
		Timer(_STRING strName);
		virtual ~Timer();

	public:
		/// 精准计时
		void				Exact();

		/// 运行定时器
		bool				Start(TimeTicks ttInterval = 0);
		/// 停止定时器
		void				Stop();
	
		/// 获得定时器名称
		_STRING				GetName();

		/// 定时器是否正在运行
		bool				IsRun();

	public:
		/// 当定时器响应时
		virtual void			OnRunTimer();

	private:
		void				Update();

	private:
		_STRING				m_strName;
		TimeTicks			m_ttSave;
		bool				m_isRun;
	};
}
#endif
